//
//  RW_LoginView.m
//  SleepApp
//
//  Created by chuangqi on 2021/3/30.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_LoginView.h"
#import "RW_InputCollectionViewCell.h"
#import "RW_ButtonCollectionViewCell.h"
#import "RW_ItemButtonCollectionViewCell.h"
#import "RW_LoginViewController.h"

@interface RW_LoginView ()
@property (nonatomic,strong) WLCollectionView *wlclass_collection_view;
@end
@implementation RW_LoginView
- (instancetype)init
{
    self = [super init];
    if (self) {
        [self addSubview:self.wlclass_collection_view];
        [self.wlclass_collection_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
    }
    return self;
}
#pragma mark -- 数据绑定
/** 初始化数据 */
-(void)initData{
    [self.wlclass_view_model getViewSuccess:^(NSArray<WLBaseCollectionViewLayerSection *> *response) {
        [self.wlclass_collection_view setAllSection:response];
    } fail:^(NSError *error) {
        
    }];
}
#pragma mark -- 逻辑操作
#pragma mark -- 代理
//点击cell的响应
- (void)wl_collectionView:(UICollectionView *)collectionView
               layerModel:(WLBaseCollectionViewLayerModel *)layerModel
             layerRowData:(id)rowData
             didIndexPath:(NSIndexPath *)indexPath{
    if ([rowData isKindOfClass:RW_InputCollectionViewCellModel.class]){
        
    } else if ([rowData isKindOfClass:RW_ButtonCollectionViewCellModel.class]){//点击按钮
        RW_ButtonCollectionViewCellModel *model = rowData;
        [SVProgressHUD showMask_wl];
        [self.wlclass_view_model netWorkLayerModel:layerModel success:^(id response) {
            if (model.button_type == Cell_Button_Type_Login){//点击登陆
                [SVProgressHUD showSuccess_wl:@"登陆成功"];
            } else if (model.button_type == Cell_Button_Type_Register){//点击注册
                [SVProgressHUD showSuccess_wl:@"注册成功，请登录"];
            }
            [[self viewController_wl].navigationController popViewControllerAnimated:YES];
        } fail:^(NSError *error) {
            [SVProgressHUD showError_wl:error.domain];
        }];
    } else if ([rowData isKindOfClass:RW_ItemButtonCollectionViewCellModel.class]){//点击其他按钮
        RW_ItemButtonCollectionViewCellModel *model = rowData;
        //短信登陆
        if (model.item_button_type == Cell_Item_Button_Type_Message){
            
        }
        //注册
        else if (model.item_button_type == Cell_Item_Button_Type_Register){
            [RW_LoginViewController pushRegisterFromVc:[self viewController_wl]];
        }
        //用户协议
        else if (model.item_button_type == Cell_Item_Button_Type_Agreement){
            
        }
    }
}


#pragma mark -- 懒加载
-(RW_LoginViewModel *)wlclass_view_model{
    if (!_wlclass_view_model){
        _wlclass_view_model = [[RW_LoginViewModel alloc]init];
    }
    return _wlclass_view_model;
}
-(WLCollectionView *)wlclass_collection_view{
    if (!_wlclass_collection_view){
        _wlclass_collection_view = [WLCollectionView initWithVerticalDelegate:self];
    }
    return _wlclass_collection_view;
}

@end
